package com.zhekou.web.action;

import net.sourceforge.stripes.action.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * User: chjp
 * Date: 11-9-3
 * Time: 下午4:09
 */
public class BaseAction implements ActionBean {
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected ActionBeanContext actionBeanContext;
    static String jspPath = "/WEB-INF/view";
    protected int curPage = 1;
    protected int pageSize = 15;

    @Override
    public void setContext(ActionBeanContext actionBeanContext) {
        this.actionBeanContext = actionBeanContext;
        this.request = actionBeanContext.getRequest();
        this.response = actionBeanContext.getResponse();
    }

    @Override
    public ActionBeanContext getContext() {
        return actionBeanContext;
    }

    @DontValidate
    public static Resolution getResolution(String view) {
        return new ForwardResolution(jspPath + "/" + view + ".jsp");
    }

    @DontValidate
    public static Resolution getAdminResolution(String view) {
        return new ForwardResolution(jspPath + "/admin/" + view + ".jsp");
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void flushBrowser() {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
    }

    public void putMsgs(String msg) {
        request.getSession().setAttribute("message", msg);
    }

    public void putError(String error) {
        request.getSession().setAttribute("error", error);
    }

}
